package com.example.javaairportflightanalysis.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import com.example.javaairportflightanalysis.common.ApiRestResponse;
import com.example.javaairportflightanalysis.domin.check.DfdlCheckAD;
import com.example.javaairportflightanalysis.domin.check.TransferCheckAD;
import com.example.javaairportflightanalysis.service.CheckService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 审核人审核的接口
 */
@RestController
@RequestMapping("/check")
@CrossOrigin(origins = "*",maxAge = 3600)
@Slf4j
//@SaCheckLogin
@SaCheckRole("ROLE_AUDITOR")
public class CheckController {
    @Resource
    CheckService checkService;
    @GetMapping("/allcheck")
    public ApiRestResponse allcheck(Integer pageNum, Integer pageSize){
        PageInfo pageInfo = checkService.selectAllDate(pageNum, pageSize);
        return ApiRestResponse.success(pageInfo);
    }

    /**
     * A2航班的审核
     */
    @GetMapping("/compareDateA2")
    public ApiRestResponse compareDateA2(Integer id){
        List<Object> compareDateA2 = checkService.selectCompareDateA2(id);
        return ApiRestResponse.success(compareDateA2);
    }
    @PostMapping("/refuseA2")
    public ApiRestResponse refuseA2(@RequestBody DfdlCheckAD dfdlCheckAD){
        checkService.refuserCheckA2(dfdlCheckAD);
        return ApiRestResponse.success();
    }
    @PostMapping("/acceptA2")
    public ApiRestResponse acceptA2(@RequestBody DfdlCheckAD dfdlCheckAD){
        checkService.acceptCheckA2(dfdlCheckAD);
        return ApiRestResponse.success();
    }

    /**
     * A3航班的审核
     */
    @GetMapping("/compareDateA3")
    public ApiRestResponse compareDateA3(Integer id){
        List<Object> compareDateA3 = checkService.selectCompareDateA3(id);
        return ApiRestResponse.success(compareDateA3);
    }
    @PostMapping("/refuseA3")
    public ApiRestResponse refuseA3(@RequestBody TransferCheckAD transferCheckAD){
        checkService.refuserCheckA3(transferCheckAD);
        return ApiRestResponse.success();
    }
    @PostMapping("/acceptA3")
    public ApiRestResponse acceptA3(@RequestBody TransferCheckAD transferCheckAD){
        log.info("transferCheckAD:{}",transferCheckAD);
        checkService.acceptCheckA3(transferCheckAD);
        return ApiRestResponse.success();
    }

    /**
     * D2航班的审核
     */
    @GetMapping("/compareDateD2")
    public ApiRestResponse compareDateD2(Integer id){
        List<Object> compareDateD2 = checkService.selectCompareDateD2(id);
        return ApiRestResponse.success(compareDateD2);
    }
    @PostMapping("/refuseD2")
    public ApiRestResponse refuseD2(@RequestBody DfdlCheckAD dfdlCheckAD){
        checkService.refuserCheckD2(dfdlCheckAD);
        return ApiRestResponse.success();
    }
    @PostMapping("/acceptD2")
    public ApiRestResponse acceptD2(@RequestBody DfdlCheckAD dfdlCheckAD){
        checkService.acceptCheckD2(dfdlCheckAD);
        return ApiRestResponse.success();
    }

    /**
     * D3航班的审核
     */
    @GetMapping("/compareDateD3")
    public ApiRestResponse compareDateD3(Integer id){
        List<Object> compareDateD3 = checkService.selectCompareDateD3(id);
        return ApiRestResponse.success(compareDateD3);
    }
    @PostMapping("/refuseD3")
    public ApiRestResponse refuseD3(@RequestBody TransferCheckAD transferCheckAD){
        checkService.refuserCheckD3(transferCheckAD);
        return ApiRestResponse.success();
    }
    @PostMapping("/acceptD3")
    public ApiRestResponse acceptD3(@RequestBody TransferCheckAD transferCheckAD){
        log.info("transferCheckAD:{}",transferCheckAD);
        checkService.acceptCheckD3(transferCheckAD);
        return ApiRestResponse.success();
    }

}
